package com.example.week04_work2;

/**
 * @author nhsoft.ll
 */
public class JoinDemo {

    public static void main(String[] args) throws Exception {
        JoinDemoSumTask sumTask = new JoinDemoSumTask();

        long start = System.currentTimeMillis();
        sumTask.start();
        sumTask.join();
        System.out.println("异步计算结果为：" + sumTask.getResult());
        System.out.println("使用时间：" + (System.currentTimeMillis() - start) + " ms");
    }
}

class JoinDemoSumTask extends Thread {

    private int result;

    public int getResult() {
        return result;
    }

    @Override
    public void run() {
        result = sum();
        System.out.println("线程运行结果:" + result);
    }

    private int sum() {
        return fibo(36);
    }

    private int fibo(int a) {
        if (a < 2)
            return 1;
        return fibo(a - 1) + fibo(a - 2);
    }
}
